package org.groupg.practice.collections;

import org.apache.commons.collections4.SetUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class SetUtilsExample {

    public static void main(String[] args) {
        // 创建两个集合
        Set<String> set1 = new HashSet<>(Arrays.asList("a", "b", "c"));
        Set<String> set2 = new HashSet<>(Arrays.asList("b", "c", "d"));

        // 求交集
        Set<String> intersection = SetUtils.intersection(set1, set2);
        System.out.println("Intersection: " + intersection); // 输出: [b, c]

        // 求并集
        Set<String> union = SetUtils.union(set1, set2);
        System.out.println("Union: " + union); // 输出: [a, b, c, d]

        // 求差集
        Set<String> subtract = SetUtils.difference(set1, set2);
        System.out.println("Subtract: " + subtract); // 输出: [a]

        // 判断两个集合是否相等（不考虑顺序）
        boolean isEqualSet = SetUtils.isEqualSet(set1, set2);
        System.out.println("Are set1 and set2 equal? " + isEqualSet); // 输出: false

        // 创建一个不可修改的集合
        Set<String> unmodifiableSet = SetUtils.unmodifiableSet(set1);
        System.out.println("Unmodifiable set: " + unmodifiableSet); // 输出: 不可修改的集合
    }
}